<?php
namespace app\modules\content\controllers;

use Yii;
use ac\controllers\AuthController;
use app\models\Config;
use ac\component\exception\ErrMap;
use ac\component\tool\Tool;
use app\models\OperationLog;


class ConfigController extends AuthController
{

    public function actionIndex()
    {
        /*取出单个数据*/
        if(Yii::$app->request->isGet){
            $config = Config::find()->asArray()->one();
            // P($config);
            if(!is_null($config)){
                if(!empty($config['company_logo'])){
                    $config['company_logo'] = explode(',', $config['company_logo']);
                }
                // P($config);
                return Tool::showRes([0, '获取成功'], $config);
            }else{
                return Tool::showRes(ErrMap::getError(10010));
            };
        }

        if(Yii::$app->request->isPost){
            $config = new Config;
            $res = $config->modifyConfig($this->post);
            if($res === true){
                $backInfo = [0, '修改配置信息成功'];//返回信息
            }else if(gettype($res) == 'array'){
                $backInfo = ErrMap::getError(10005);//返回信息
                $exception = $res;
            }
        }

        if(!isset($backInfo)){
            $backInfo = ErrMap::getError(10005);//返回信息
        }
        if(!isset($exception)){
            $exception = '';//异常信息
        }
        //操作日志
        if(gettype( $res = OperationLog::addLog(Tool::operationLogArgs($backInfo, $this->userInfo), $exception) ) != 'boolean'){
            return $res;
        };
    }


}
